#include <iostream>
#include<algorithm>
#include <string.h>
#include<fstream>
#include<time.h>
#include<stack>
#include<vector>
#include<sstream>
using namespace std;

int main()
{
	int n;
	while (cin >> n) 
	{
		int *arr = new int[n];
		int *brr = new int[n];
		int Max = 0;
		for(int i=0;i<n;i++)
		{
			cin >> arr[i];
			if (Max < arr[i])Max = arr[i];
		}
		for (int i = 0; i<n; i++)
		{
			cin >> brr[i];
		}
		int MaxTime = Max*n;
		vector< vector<int> >dp(n + 1, vector<int>(MaxTime+1,0));
		for (int i = 1; i<= n; i++)
		{
			for (int j = 0; j <= MaxTime; j++)
			{
				if (j - arr[i - 1] >= 0)
					dp[i][j] = min(dp[i - 1][j] + brr[i - 1], dp[i - 1][j - arr[i - 1]]);
				else
					dp[i][j] = dp[i - 1][j] + brr[i - 1];

			}
		}
		Max = 0x3f3f3f3f;
		for (int i = 0; i <= MaxTime; i++)
		{
			Max = min(max(i,dp[n][i]),Max);
		}
		cout << Max << endl;
	}
	return 0;
}